package com.happy.controller;

import com.happy.entity.CategoryEntity;
import com.happy.service.ICategoryService;
import com.happy.util.ResultBody;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Wuzh
 * @Description:
 * @Date Created in 22:23 2021/2/18
 * @return
 */
@RestController
@RequestMapping ("/category")
@CrossOrigin (value = "*", maxAge = 3600)
public class CategoryController {


    @Resource
    private ICategoryService iCategoryService;


    @RequestMapping ("/queryList")
    public ResultBody<CategoryEntity> queryList ( CategoryEntity categoryEntity ) {
        List<CategoryEntity> categoryEntities = iCategoryService.queryList ( categoryEntity );
        return ResultBody.success ( categoryEntities, categoryEntities.size () );
    }


    @RequestMapping ("/addSingle")
    public ResultBody<CategoryEntity> addSingle ( @RequestBody CategoryEntity categoryEntity ) {
        categoryEntity = iCategoryService.addSingle ( categoryEntity );
        return ResultBody.success ( categoryEntity );
    }

}
